<%--
    Document   : index
    Created on : 27 janv. 2010, 16:38:12
    Author     : Sébastien Szymanski
--%>
<%
	    String passwordContext = (String) getServletContext().getAttribute("password");
	    if(passwordContext == null)
		getServletContext().setAttribute("password", getServletContext().getInitParameter("passwordDefault"));
%>

<%@page contentType="text/html" pageEncoding="UTF-8" import="fr.uha.ensisa.kfetmanager.product.ProductManagerRemote,
        fr.uha.ensisa.kfetmanager.product.Product,
        javax.naming.*,
        java.util.*"%>

<%! 
    private ProductManagerRemote productManager = null;
    private boolean initializationSuccess = false;

    public void jspInit() {
	InitialContext ctxt = null;
	String name = ProductManagerRemote.class.getName();
	try {
	    ctxt = new InitialContext();
	}
	catch(Exception e) {
	    System.err.println("Naming exception caught on new InitialContext().");
	    e.printStackTrace();
	    return;
	}
	try {
	    productManager = (ProductManagerRemote) ctxt.lookup(name);
	}
	catch(Exception e) {
	    System.err.println("Naming exception caught on lookup.");
	    e.printStackTrace();
	    return;
	}
	
	initializationSuccess = true;
    }
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" media="screen" href="css/main.css" />
	<script type="text/javascript" src="javascript/prototype.js"></script>
	<script type="text/javascript;e4x=1" src="javascript/customers.js"></script>
	<title>Kfet' Manager</title>
    </head>

    <body onload="init()">
	<div id="header">
	    Kfet' Manager 2010 [<a href="admin">admin</a>]
	</div>

	<div id="customers">
	    <p class="title">Clients</p>

	    <input type="text" id="customerName" value="" onkeyup="customersRequest()" />

	    <p class="title">R&eacute;sultats</p>

	    <table id="customersTable">
	    </table>
	</div>

	<div id="products">
	    <p class="title">Produits</p>
	    <%
		if(initializationSuccess) {
		    List<Product> list;

		    try {
			list = productManager.getProducts();
			Iterator<Product> it = list.iterator();

			int i = 1;
			while(it.hasNext()) {
			    Product p = it.next();

			    out.write("<a href=\"javascript:order.addProduct(" + p.getId() + ")\">" + p.getName() + "</a> ");

			    if(i % 2 == 0)
				out.write("<br />");

			    i++;
			}
		    }
		    catch(Exception e) {
		    }
		}
	    %>
	</div>

	<div id="transaction">
	    <p class="title">Transaction</p>

	    <p class="subtitle">Client</p>
	    <p id="customerInfo">
		S&eacute;lectionner un client en utilisant la zone <i>Clients</i>.
	    </p>

	    <p class="subtitle">Commande</p>
	    <table id="productsList">
		<tr><td style="text-align: center;">S&eacute;lectionner un ou plusieurs produit en utilisant la zone <i>Produits</i>.</td></tr>
	    </table>

	    <p class="subtitle" id="cmdTransaction" style="display: none;">Cr&eacute;diter</p>

	    <div id="crediterForm" style="display:none; margin-top: 1%;">
		<p>Somme : <input type="text" id ="crediterMoney" name="crediterMoney" value="" /></p>
		<p>Password : <input type="password" id="crediterPassword" name="crediterPassword" value="" /></p>
		<p><input type="submit" id="crediterButton" name="crediterButton" value="Cr&eacute;diter" /></p>
	    </div>
	</div>
    </body>
</html>
